
<template>
  <div>
    <van-nav-bar
      :title="comment.reply_count ? comment.reply_count+'条回复':'暂无回复'"
    >
      <template #left>
        <van-icon name="cross" @click="$emit('close')" />
      </template>
    </van-nav-bar>

    <div class="scroll-wrap">
      <comment-item :comment="comment" />
      <van-cell title="全部回复" />

      <comment-list
        :list="commentList"
        :source="comment.com_id + ''"
        type="c"
      />
    </div>

    <!-- 底部区域 -->
    <div class="reply-bottom">
      <van-button
        class="write-btn"
        size="small"
        round
        @click="isShow = true"
      >写评论</van-button>
    </div>
    <!-- /底部区域 -->

    <!-- 发布评论 -->
    <van-popup v-model="isShow" position="bottom">
      <comment-post
        :target="comment.com_id + ''"
        :article-id="articleId"
        @on-success="onSuccess"
      />
    </van-popup>
    <!-- /发布评论 -->
  </div>
</template>

<script>
import CommentItem from '../../../components/CommentItem.vue'
import CommentList from '../../Detail/compoents/CommentList.vue'
import CommentPost from '../../Detail/compoents/CommentPost.vue'
export default {
  components: { CommentItem, CommentList, CommentPost },
  inject: {
    articleId: {
      type: [Number, String, Object],
      default: null
    }
  },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      commentList: [],
      isShow: false
    }
  },

  created() {

  },

  methods: {
    onSuccess(data) {
      this.comment.reply_count++
      // console.log(data)
      this.commentList.unshift(data)
      this.isShow = false
    }
  }
}
</script>

<style scoped lang='less'>
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}

.reply-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .write-btn {
    width: 60%;
  }
}
</style>
